package lk.icta.core.entity;

import lk.icta.user.entity.User;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @author Kusal Samarakoon
 */

@Entity
@Table(schema = "ELAND_RAIL")
@NamedQueries({
        @NamedQuery(
                name = "getAllCalenderSchedule", query = "SELECT a FROM CalenderSchedule a " +
                        "WHERE a.active=1 AND a.lifeCycleInfo.createdUser = :user "
        ),
        @NamedQuery(name = "getAllCalenderScheduleByUser", query = "SELECT a FROM CalenderSchedule  a " +
                "WHERE a.active=1 AND :user MEMBER OF a.users "),

        @NamedQuery(name = "getAllCalenderScheduleByCalenderScheduleType", query = "SELECT a FROM CalenderSchedule  a " +
                "WHERE a.active=1 AND a.calenderScheduleType = :scheduleType ")
})

public class CalenderSchedule implements Serializable {

    //Todo: no need to use two ids, remove one attribute. Dont use String for id field
    @Id
    @Column(nullable = false)
    private String calenderId;

    //todo: Bad naming. Why this is named as count  if this is an IDENTITY. No usage found
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int count_id;

    @Column(nullable = true)
    private String title;

    @Column(nullable = true)
    private String location;

    @Column(nullable = true)
    private String details;

    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date startDate;

    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date endDate;

    //todo: Bad naming
    @Column(nullable = true)
    private String start_time;

    @Column(nullable = true)
    private CalenderScheduleType calenderScheduleType;

    @Column(nullable = true)
    private String end_time;


    @ManyToOne
    @JoinColumn(nullable = true)
    private Organization organization;

    @Column(nullable = true)
    private boolean active;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(schema = "ELAND_RAIL")
    private List<User> users;

    @Embedded
    private LifeCycleInfo lifeCycleInfo = new LifeCycleInfo();

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getStart_time() {
        return start_time;
    }

    public void setStart_time(String start_time) {
        this.start_time = start_time;
    }

    public String getEnd_time() {
        return end_time;
    }

    public void setEnd_time(String end_time) {
        this.end_time = end_time;
    }


    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public LifeCycleInfo getLifeCycleInfo() {
        return lifeCycleInfo;
    }

    public void setLifeCycleInfo(LifeCycleInfo lifeCycleInfo) {
        this.lifeCycleInfo = lifeCycleInfo;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getCalenderId() {
        return calenderId;
    }

    public void setCalenderId(String calenderId) {
        this.calenderId = calenderId;
    }


    public int getCount_id() {
        return count_id;
    }

    public void setCount_id(int count_id) {
        this.count_id = count_id;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }


    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public CalenderScheduleType getCalenderScheduleType() {
        return calenderScheduleType;
    }

    public void setCalenderScheduleType(CalenderScheduleType calenderScheduleType) {
        this.calenderScheduleType = calenderScheduleType;
    }
}
